package com.SouthernWall_404.AgeRight.Common.Event;

import com.SouthernWall_404.AgeRight.Common.API.Capability.Missions;
import com.SouthernWall_404.AgeRight.Common.API.Capability.Provider.MissionsProvider;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = "ageright", bus = Mod.EventBusSubscriber.Bus.FORGE)
public class KillEventHandler {
    
    @SubscribeEvent
    public static void onEntityKilled(LivingDeathEvent event) {
        // 检查是否有玩家造成了这次击杀
        if (event.getSource().getEntity() instanceof Player) {
            Player player = (Player) event.getSource().getEntity();
            LivingEntity killedEntity = event.getEntity();
            
            // 在服务器端处理
            if (!player.level().isClientSide()) {
                player.getCapability(MissionsProvider.MISSIONS_CAPABILITY).ifPresent(missions -> {
                    missions.checkKill(killedEntity, player);
                });
            }
        }
    }
}